Home Assistant Wake Up Alarm Trigger Automation
This assumes you've already set up the companion Home Assistant app to your phone an enabled the Alarm Sensors
Testing in Editor
Utilize the template playground editor to understand how to create a template. http://YOUR_HA_IP:8123/developer-tools/template
isAlarmRinging: {{now().strftime("%a %h %d %H:%M %Z %Y") ==
(((state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') |
int / 1000)) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}
{# extra examples to understand above code #}
{% set timeNow = now().strftime("%a %h %d %H:%M %Z %Y") %}
{% set myAlarm = (state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') | int / 1000) | timestamp_custom('%a %h %d %H:%M %Z %Y') %}
timeNow: {{ timeNow }}
myAlarm: {{ myAlarm }}
The output 'Result' should look like
isAlarmRinging: False
timeNow: Wed Oct 02 13:17 CDT 2024
myAlarm: Thu Oct 03 06:12 CDT 2024
phone_next_alarm
with the unique name of your phone sensor
On Your Phone
You should be able to set the alarm and watch the myAlarm
update in real time. When the timeNow
and myAlarm
match you should see isAlarmRinging: True
just for a split second.
You may miss it with the naked eye, but the computer will recognize it as a trigger for automation.
Configuration.yaml
Now e can move on to creating the sensor in .yml
. I've code split my templates into a seperate template.yaml
.
## configuration.yaml
template: !include template.yaml
## template.yaml
- sensor:
- name: "isAlarmRinging_myphone"
# state: false
state: >
{{now().strftime("%a %h %d %H:%M %Z %Y") ==
(((state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') |
int / 1000)) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}
don't forget to change phone_next_alarm
and isAlarmRinging_myphone
to your needs
Home Assistant
Move to the HA UI in your browser to restart home assistant. Confirm the sensor was created at http://hYOUR_HA_IP:8123/config/entities and make sure it's showing as False
Automation
The automation I've set up with this alarm turns on my lights for my wake up morning routine.
This routine logic:
- Trigger when current time equals alarm time (When
isAlarmRinging_myphone
goesFalse
toTrue
) - and if time is between 5am - 9am
- activate wake up scene